package edu.hawaii.halealohacli.kmj;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Command class that prints information about the valid program arguments.
 * 
 * @author Richard Kamana Akina, modified by Jordan Takayama
 *
 */
public class HelpCommand implements Command {
  /**
   * Contains help text for the program's commands.
   */
  private String helpString = null;
  /**
   * Constructor.
   */
  public HelpCommand() {
    InputStream fstream = null;
    BufferedReader br = null;
    String strLine;
    try {
      // Code source: 
      // <http://stackoverflow.com/questions/5054435/reading-file-in-jar-using-relative-path>
      // Files inside a jar have to be retrieved as a stream first. - Jordan Takayama, 2011-12-06
      fstream = getClass().getResourceAsStream("help.txt");      
      br = new BufferedReader(new InputStreamReader(fstream, "UTF-8"));
      while ((strLine = br.readLine()) != null) {
        helpString += ("\n" + strLine);
      }
    }
    catch (Exception e) {
      System.err.println("Error: " + e.getMessage());
    }
    finally {
      try {
        fstream.close();
        br.close();
      }
      catch (Exception e) {
        System.err.println("Error: " + e.getMessage());
      }
    }
  }
  
  /**
   * Prints help information.
   */
  @Override
  public void printResult() {
    System.out.println(this.helpString);
  }

}
